package se.webbzon.boltzmann.player;

public class PlayerLevel {
	
	// The maximal level the player can reach
	public static final int topLevel = 25;
	
	// The level and the notes of this level
	private int level, notes;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new player level starting at level one with 
	 * zero notes.**/
	public PlayerLevel() {
		this(1,0);
	}
	
	/** Creates a new player level with the given starting level
	 * and the given amount of notes. **/
	public PlayerLevel(int level, int notes) {
		this.level = (level > topLevel) ? topLevel : level;
		this.notes = notes;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the level of the player. **/
	public int getLevel() {
		return level;
	}

	/** Sets the level of the player. **/
	public void setLevel(int level) {
		this.level = level;
	}

	/** Returns the amount of collected notes. **/
	public int getNotes() {
		return notes;
	}

	/** Sets the amount of notes collected. **/
	public void setNotes(int notes) {
		addNotes(notes - this.notes);
	}
	
	/** Adds the given amount of notes to the player level. **/
	public void addNotes(int notes) {
		if (notes >= requiredNotes()) {
			if (level < topLevel) {
				level++;
				addNotes(notes - requiredNotes());
			} else {
				level = topLevel;
				this.notes = requiredNotes() - 1;
			}
		} else
			this.notes += notes;
	}
	
	/** Returns the number of notes required to reach the next level. **/
	public int requiredNotes() {
		return 60 * level + 10;
	}

}
